﻿/*
*┌────────────────────────────────────────────────┐
*│　描    述：HospitalInfoDAL                                                   
*│　作    者： (Jxw)                                             
*│　版    本：1.0                                              
*│　创建时间：2020/7/9 17:21:35                        
*└────────────────────────────────────────────────┘
*/
using Model;
using Model.Enum;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utility;

namespace DAL
{
    public class HospitalInfoDAL
    {

        #region 车组信息接口
        public ResponseDataDTO GetAmbulanceList()
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取车组信息成功！" };
            AmbulanceList ambulanceList = new AmbulanceList();
            List<AmbulanceInfoDTO> list = new List<AmbulanceInfoDTO>();
            List<ambStateList> ambStateLists = new List<ambStateList>();
            List<ambAreaList> ambAreaLists = new List<ambAreaList>();
            List<ambAreas> ambAreasDTO;

            try
            {
                StringBuilder sb = new StringBuilder(@"   
                                select tc.名称,
                                任务中=isnull(sum(case when tz.编码>=0 and tz.编码<=5 then 1 else 0 end ),0) ,
                                ts.中心编码
                                from   TAmbulance  ta  
								left join TTask tt on ta.任务编码=tt.任务编码
								left join TAlarmEvent te on te.事件编码=tt.事件编码
                                left join  TStation  ts on ta.分站编码=ts.编码
                                left join  TCenter   tc  on  ts.中心编码=tc.编码
                                left join  TZAmbulanceState  tz on  tz.编码=ta.工作状态编码
                                where ta.是否在线=1  and   te.事件类型编码=1 and tt.是否执行中=1
                                group by  tc.名称,ts.中心编码
                                order by  tc.名称 desc");
                StringBuilder sb1 = new StringBuilder(@"                                  
                                select tc.名称,
                                待命车组=isnull(sum(case when tz.编码>=6 and tz.编码<=7 then 1 else 0 end ),0) ,
                                暂停调用=isnull(sum(case when tz.编码>=8 and tz.编码<=9 then 1 else 0 end ),0) ,
                                ts.中心编码
                                from   TAmbulance  ta  
                                left join  TStation  ts on ta.分站编码=ts.编码
                                left join  TCenter   tc  on  ts.中心编码=tc.编码
                                left join  TZAmbulanceState  tz on  tz.编码=ta.工作状态编码
                                where ta.是否在线=1
                                group by  tc.名称,ts.中心编码
                                order by  tc.名称 desc");
                DataSet ds = DataSetUtility.GetDataSetFromMain(sb);
                DataSet ds1 = DataSetUtility.GetDataSetFromMain(sb1);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        AmbulanceInfoDTO ambulanceInfo = new AmbulanceInfoDTO();
                        ambulanceInfo.center = dr["名称"].ToString();
                        ambulanceInfo.task = NullConvert.IntNullDispose(dr["任务中"].ToString());
                        ambulanceInfo.centerId = dr["中心编码"].ToString();
                        ambulanceInfo.work = ambulanceInfo.task + ambulanceInfo.wait + ambulanceInfo.stop;
                        list.Add(ambulanceInfo);
                    }
                    if (ds1.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in ds1.Tables[0].Rows)
                        {
                            string name = dr["名称"].ToString();
                            if (list.Exists(x => x.center == name))
                            {
                                list.ForEach(item =>
                                {
                                    if (item.center == name)
                                    {
                                        item.wait = NullConvert.IntNullDispose(dr["待命车组"].ToString());
                                        item.stop = NullConvert.IntNullDispose(dr["暂停调用"].ToString());
                                        item.work = item.task + item.wait + item.stop;
                                    }

                                });
                            }
                            else
                            {

                                AmbulanceInfoDTO ambulanceInfo = new AmbulanceInfoDTO();
                                ambulanceInfo.center = name;
                                ambulanceInfo.task = 0;
                                ambulanceInfo.wait = NullConvert.IntNullDispose(dr["待命车组"].ToString());
                                ambulanceInfo.stop = NullConvert.IntNullDispose(dr["暂停调用"].ToString());
                                ambulanceInfo.work = ambulanceInfo.task + ambulanceInfo.wait + ambulanceInfo.stop;
                                ambulanceInfo.centerId = dr["中心编码"].ToString();
                                list.Add(ambulanceInfo);

                            }
                        }

                        #region 车组状态信息

                        ambStateLists.Add(new ambStateList()
                        {
                            name = "值班中",
                            color = "#55a8eb",
                            count = list.Sum(x => x.work)
                        });
                        ambStateLists.Add(new ambStateList()
                        {
                            name = "任务中",
                            color = "#db373a",
                            count = list.Sum(x => x.task)
                        });
                        ambStateLists.Add(new ambStateList()
                        {
                            name = "待命中",
                            color = "#27ae60",
                            count = list.Sum(x => x.wait)
                        });
                        ambStateLists.Add(new ambStateList()
                        {
                            name = "暂停调用",
                            color = "#999999",
                            count = list.Sum(x => x.stop)
                        });

                        #endregion

                        #region 车组地区信息
                        List<string> zs = new List<string> { "21", "22", "23", "24", "25", "26", "27", "50" };//直属
                        List<string> cq = new List<string> { "14", "47", "12", "13", "16" };//城区
                        List<string> jq = new List<string> { "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "17" };//郊区
                        string hh = "52";//红会

                        #region 直属
                        var zsList = list.Where(x => zs.Contains(x.centerId)).ToList();
                        ambAreasDTO= new List<ambAreas>();
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "任务",
                            color = "#db373a",
                            value = zsList.Sum(x => x.task),
                        });
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "待命",
                            color = "#27ae60",
                            value = zsList.Sum(x => x.wait),
                        });
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "暂停",
                            color = "#999999",
                            value = zsList.Sum(x => x.stop),
                        });

                        ambAreaLists.Add(
                           new ambAreaList()
                           {
                               name = "直属",
                               data = ambAreasDTO
                           }
                           );
                        #endregion

                        #region 城区
                        var cqList = list.Where(x => cq.Contains(x.centerId)).ToList();
                        ambAreasDTO = new List<ambAreas>();
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "任务",
                            color = "#db373a",
                            value = cqList.Sum(x => x.task),
                        });
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "待命",
                            color = "#27ae60",
                            value = cqList.Sum(x => x.wait),
                        });
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "暂停",
                            color = "#999999",
                            value = cqList.Sum(x => x.stop),
                        });
                        ambAreaLists.Add(
                            new ambAreaList()
                            {
                                name = "城区",
                                data = ambAreasDTO
                            }
                            );
                        #endregion


                        #region 郊区
                        var jqList = list.Where(x => jq.Contains(x.centerId)).ToList();
                        ambAreasDTO = new List<ambAreas>();

                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "任务",
                            color = "#db373a",
                            value = jqList.Sum(x => x.task),
                        });
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "待命",
                            color = "#27ae60",
                            value = jqList.Sum(x => x.wait),
                        });
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "暂停",
                            color = "#999999",
                            value = jqList.Sum(x => x.stop),
                        });
                        ambAreaLists.Add(
                           new ambAreaList()
                           {
                               name = "郊区",
                               data = ambAreasDTO
                           }
                           );
                        #endregion


                        #region 红会
                        var hhList = list.Where(x => x.centerId == hh).ToList();
                        ambAreasDTO = new List<ambAreas>() { };
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "任务",
                            color = "#db373a",
                            value = hhList.Sum(x => x.task),
                        });
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "待命",
                            color = "#27ae60",
                            value = hhList.Sum(x => x.wait),
                        });
                        ambAreasDTO.Add(new ambAreas()
                        {
                            name = "暂停",
                            color = "#999999",
                            value = hhList.Sum(x => x.stop),
                        });
                        ambAreaLists.Add(
                           new ambAreaList()
                           {
                               name = "红会",
                               data = ambAreasDTO
                           }
                          );
                        #endregion


                        #endregion

                        ambulanceList.ambStateLists = ambStateLists;
                        ambulanceList.ambAreaLists = ambAreaLists;
                    }
                }
                responseData.data = ambulanceList;
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetAmbulanceList", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }


        public RetInfo<List<Hashtable>> GetCenterList(string name)
        {
            RetInfo<List<Hashtable>> ri = new RetInfo<List<Hashtable>>(true);
            try
            {
                List<Hashtable> list = new List<Hashtable>();
                StringBuilder sb = new StringBuilder(@"   
                                select tc.名称,
                                任务中=isnull(sum(case when tz.编码>=0 and tz.编码<=5 then 1 else 0 end ),0) ,
                                ts.中心编码
                                from   TAmbulance  ta  
								left join TTask tt on ta.任务编码=tt.任务编码
								left join TAlarmEvent te on te.事件编码=tt.事件编码
                                left join  TStation  ts on ta.分站编码=ts.编码
                                left join  TCenter   tc  on  ts.中心编码=tc.编码
                                left join  TZAmbulanceState  tz on  tz.编码=ta.工作状态编码
                                where ta.是否在线=1  and   te.事件类型编码=1 and tt.是否执行中=1
                                group by  tc.名称,ts.中心编码
                                order by  tc.名称 desc");
                StringBuilder sb1 = new StringBuilder(@"                                  
                                select tc.名称,
                                待命车组=isnull(sum(case when tz.编码>=6 and tz.编码<=7 then 1 else 0 end ),0) ,
                                暂停调用=isnull(sum(case when tz.编码>=8 and tz.编码<=9 then 1 else 0 end ),0) ,
                                ts.中心编码
                                from   TAmbulance  ta  
                                left join  TStation  ts on ta.分站编码=ts.编码
                                left join  TCenter   tc  on  ts.中心编码=tc.编码
                                left join  TZAmbulanceState  tz on  tz.编码=ta.工作状态编码
                                where ta.是否在线=1
                                group by  tc.名称,ts.中心编码
                                order by  tc.名称 desc");
                DataSet ds = DataSetUtility.GetDataSetFromMain(sb);
                DataSet ds1 = DataSetUtility.GetDataSetFromMain(sb1);

                if (name == "task")
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        Hashtable ht;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            ht = new Hashtable();
                            ht.Add("name", dr["名称"]);
                            ht.Add("value", Convert.ToInt32(dr["任务中"].ToString()));
                            list.Add(ht);
                        }
                    }
                    if (list.Count > 0)
                    {
                        ri.data = list;
                    }
                    else
                    {
                        ri.ret = false;
                        ri.res = "未获取到数据";
                    }
                    return ri;
                }
                else
                {
                    if (ds1.Tables[0].Rows.Count > 0)
                    {
                        Hashtable ht;
                        if (name == "work")
                        {
                            List<ambCenterList> ambCenterLists = new List<ambCenterList>();
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    foreach (DataRow dr1 in ds1.Tables[0].Rows)
                                    {
                                        
                                        if (dr["名称"].ToString() == dr1["名称"].ToString())
                                        {
                                            ambCenterList ambCenter = new ambCenterList();
                                            ambCenter.name = dr["名称"].ToString();
                                            int sum = Convert.ToInt32(dr["任务中"].ToString()) + Convert.ToInt32(dr1["待命车组"].ToString()) + Convert.ToInt32(dr1["暂停调用"].ToString());
                                            ambCenter.value = sum;
                                            ambCenterLists.Add(ambCenter);
                                        }
                                    }
                                }
                                foreach (DataRow dr in ds1.Tables[0].Rows)
                                {
                                    string centerName = dr["名称"].ToString();
                                    if (!ambCenterLists.Exists(x => x.name == centerName))
                                    {
                                        ambCenterList ambCenter = new ambCenterList();
                                        ambCenter.name = dr["名称"].ToString();
                                        int sum = Convert.ToInt32(dr["待命车组"].ToString()) + Convert.ToInt32(dr["暂停调用"].ToString());
                                        ambCenter.value = sum;
                                        ambCenterLists.Add(ambCenter);

                                    }
                                }
                                ambCenterLists.ForEach(q =>
                                {
                                    ht = new Hashtable();
                                    ht.Add("name", q.name);
                                    ht.Add("value", q.value);
                                    list.Add(ht);
                                });
                            }
                        }
                        else if (name == "wait")
                        {
                            foreach (DataRow dr in ds1.Tables[0].Rows)
                            {
                                ht = new Hashtable();
                                ht.Add("name", dr["名称"]);
                                ht.Add("value", Convert.ToInt32(dr["待命车组"].ToString()));
                                list.Add(ht);
                            }
                        }
                        else if (name == "stop")
                        {
                            foreach (DataRow dr in ds1.Tables[0].Rows)
                            {
                                ht = new Hashtable();
                                ht.Add("name", dr["名称"]);
                                ht.Add("value", Convert.ToInt32(dr["暂停调用"].ToString()));
                                list.Add(ht);
                            }
                        }
                        if (list.Count > 0)
                        {
                            ri.data = list;
                        }
                        else
                        {
                            ri.ret = false;
                            ri.res = "未获取到数据";
                        }
                        return ri;
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetHospitalList", ex.ToString());//记日志
                ri.ret = false;
                ri.res = ex.Message;
            }
            return ri;
        }

        #endregion


        #region 医院列表接口
        public ResponseDataDTO GetHospitalList()
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取医院信息成功！" };
            List<HospitalListDTO> hospInfoList = new List<HospitalListDTO>();
            try
            {
                StringBuilder sb = new StringBuilder(@"   select  thb.医院编码,thb.医院简称,thb.经度,thb.纬度,thb.医院级别,thr.抢救室床位,thr.抢救室使用量,thb.地址,thb.联系电话 ,thb.区域,thb.是否所属郊区  from  THospitalBaseInfo  thb  left  join   THospitalRealTimeInfo  thr  on  thb.医院编码=thr.医院编码 where thb.是否有效=1");
                //StringBuilder sb = new StringBuilder(@"   select thb.医院简称,thr.抢救室床位,thr.抢救室使用量  from  THospitalBaseInfo  thb  left  join   THospitalRealTimeInfo  thr  on  thb.医院编码=thr.医院编码 where thb.是否有效=1");
                DataSet ds = DataSetUtility.GetDataSetFromCDB(sb);
                List<TZDictionary> dictionaryList = GetTZDictionary();//获取字典数据
                if (ds.Tables[0].Rows.Count > 0)
                {
                    var  areaList=dictionaryList.Where(x => x.typeID == "District").ToList();//获取区域数据
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        HospitalListDTO hospitalInfo = new HospitalListDTO();
                        hospitalInfo.id = dr["医院编码"].ToString();
                        hospitalInfo.name = dr["医院简称"].ToString();

                        if (dr["经度"].ToString() == "0" && dr["纬度"].ToString() == "0")
                        {
                            hospitalInfo.longitude = 0;
                            hospitalInfo.latitude = 0;
                        }
                        else
                        {
                            //转成百度GPS
                            double[] coordinate = CoorConvert.Gps84ToBd09(Convert.ToDouble(dr["纬度"]), Convert.ToDouble(dr["经度"]));
                            hospitalInfo.longitude = coordinate[1];
                            hospitalInfo.latitude = coordinate[0];
                        }

                        hospitalInfo.hospLevel = dr["医院级别"].ToString();
                        hospitalInfo.address = dr["地址"].ToString();
                        hospitalInfo.telephone = dr["联系电话"].ToString();
                        //if (level.Equals(EnumHelper.GetEnumDesc(HospitalLevelEnum.HLl)))
                        //{
                        //    hospitalInfo.hospLevel = "一甲";
                        //}
                        //else if (level.Equals(EnumHelper.GetEnumDesc(HospitalLevelEnum.HL2)))
                        //{
                        //    hospitalInfo.hospLevel = "二甲";
                        //}
                        //else if (level.Equals(EnumHelper.GetEnumDesc(HospitalLevelEnum.HL3)))
                        //{
                        //    hospitalInfo.hospLevel = "三甲";
                        //}
                        //else {
                        //    hospitalInfo.hospLevel = "";
                        //}

                        hospitalInfo.areaName = areaList.FirstOrDefault(x => x.id == dr["区域"].ToString())?.name;
                        hospitalInfo.isSuburbs= Convert.ToBoolean(dr["是否所属郊区"]);


                        int bedTotal = NullConvert.IntNullDispose(dr["抢救室床位"].ToString());
                        int useAmount = NullConvert.IntNullDispose(dr["抢救室使用量"].ToString());
                        if (useAmount >= bedTotal)
                        {
                            if (bedTotal == 0)
                            {
                                hospitalInfo.sum = bedTotal;
                                hospitalInfo.used = 0;
                                hospitalInfo.percent = 0;//拥挤度百分比
                                hospitalInfo.color = "#FF0000";//红色十六进制
                            }
                            else
                            {
                                hospitalInfo.sum = bedTotal;
                                hospitalInfo.used = 0;
                                hospitalInfo.percent = 100;
                                hospitalInfo.color = "#FF0000";//红色十六进制
                            }
                        }
                        else
                        {
                            hospitalInfo.sum = bedTotal;
                            hospitalInfo.used = bedTotal - useAmount;
                            double num = Math.Round(Convert.ToDouble(useAmount) / Convert.ToDouble(bedTotal), 2) * 100;//拥挤度百分比
                            hospitalInfo.percent = Math.Round(num, 2);
                            if (num < 100 && num > 70)
                            {
                                hospitalInfo.color = "#FFFF00";//黄色十六进制
                            }
                            else if (num <= 70)
                            {
                                hospitalInfo.color = "#008000";//绿色十六进制
                            }
                        }
                        hospInfoList.Add(hospitalInfo);
                    }
                }
                responseData.data = hospInfoList;
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetHospitalList", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }

        #endregion


        #region 获取医院经纬度

        public ResponseDataDTO GetHospitalXY(string areaName)
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取医院信息成功！" };
            List<MapHospitalListDTO> hospInfoList = new List<MapHospitalListDTO>();
            try
            {
                StringBuilder sb = new StringBuilder();
                List<SqlParameter> SqlParams = new List<SqlParameter>();
                string StrWhere = "";

                if (!string.IsNullOrEmpty(areaName))
                {
                    SqlParams.Add(new SqlParameter("@areaName", areaName));
                    StrWhere += " AND  tz.名称=@areaName";
                }

                sb.Append($" select thb.医院简称,thb.经度,thb.纬度,tz.名称,thb.是否所属郊区  from THospitalBaseInfo thb" +
                    $"  left join THospitalRealTimeInfo thr  on thb.医院编码 = thr.医院编码" +
                    $"  left join TZDictionary tz  on tz.编码 = thb.区域 " +
                    $"  where thb.是否有效 = 1  and  类型编码 = 'District' {StrWhere} ");
                SqlParameter[] paramTot = SqlParams.ToArray();
                DataSet ds = DataSetUtility.GetDataSetFromCDB(sb, paramTot);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        MapHospitalListDTO hospitalInfo = new MapHospitalListDTO();
                        hospitalInfo.name = dr["医院简称"].ToString();

                        if (dr["经度"].ToString() == "0" && dr["纬度"].ToString() == "0")
                        {
                            double[] x = { 0, 0 };
                            hospitalInfo.value= x;
                        }
                        else
                        {
                            //转成百度GPS
                            double[] coordinate = CoorConvert.Gps84ToGcj02(Convert.ToDouble(dr["纬度"]), Convert.ToDouble(dr["经度"]));
                            double[] arr = { coordinate[1], coordinate[0] };
                            hospitalInfo.value = arr;
                        }
                        hospitalInfo.areaName =  dr["名称"].ToString();
                        hospitalInfo.isSuburbs = Convert.ToBoolean(dr["是否所属郊区"]);
                        hospInfoList.Add(hospitalInfo);
                    }
                }
                responseData.data = hospInfoList;
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetHospitalXY", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }
        #endregion

        #region 区域车组信息
        public ResponseDataDTO GetAreaAmbList(string areaName)
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取区域车组信息成功！" };
            List<AreaAmbList> areaAmbList = new List<AreaAmbList>();
            try
            {
                DataSet ds=new DataSet();
                StringBuilder sb = new StringBuilder();
                if (string.IsNullOrEmpty(areaName)) {
                    sb.Append(@"   select ts.所属区域,总数=isnull(sum(case when tz.编码>=0 and tz.编码<=9 then 1 else 0 end ),0)
                                from   TAmbulance  ta  
                                left join  TStation  ts on ta.分站编码=ts.编码
                                left join  TCenter   tc  on  ts.中心编码=tc.编码
                                left join  TZAmbulanceState  tz on  tz.编码=ta.工作状态编码
                                where ta.是否在线=1
                                group by ts.所属区域");
                    ds= DataSetUtility.GetDataSetFromMain(sb);
                }
                else {
                    SqlParameter sp = new SqlParameter("@areaName", areaName);
                    sb.Append(@"   select ts.所属区域,总数=isnull(sum(case when tz.编码>=0 and tz.编码<=9 then 1 else 0 end ),0)
                                from   TAmbulance  ta  
                                left join  TStation  ts on ta.分站编码=ts.编码
                                left join  TCenter   tc  on  ts.中心编码=tc.编码
                                left join  TZAmbulanceState  tz on  tz.编码=ta.工作状态编码
                                where ta.是否在线=1  and  ts.所属区域=@areaName
                                group by ts.所属区域");
                    ds = DataSetUtility.GetDataSetFromMain(sb,sp);
                }
                
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        AreaAmbList areaAmb = new AreaAmbList();
                        areaAmb.name = dr["所属区域"].ToString();
                        areaAmb.value = NullConvert.IntNullDispose(dr["总数"].ToString());
                        areaAmbList.Add(areaAmb);
                    }
                }
                responseData.data = areaAmbList;
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetAreaAmbList", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }
        #endregion

        #region 衔接统计信息接口

        public ResponseDataDTO GetToldStatistics()
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取衔接接送统计成功！" };
            List<ToldStatisticsDTO> toldDTOList = new List<ToldStatisticsDTO>();
            ToldStatisticsDTO toldDTO;
            List<ToldStatistics> toldList;
            try
            {
                StringBuilder sb = new StringBuilder(@"   
                                    select 今日=isnull(sum(case when  DateDiff(dd,创建时间,getdate())=0   then 1 else 0 end ),0) ,
                                    本月=isnull(sum(case when DateDiff(month,创建时间,getdate())=0   then 1 else 0 end ),0) 
                                    from  TToldInfo where 送往地点 is not null and 发送告知时刻  is not null");
                StringBuilder ptSb = new StringBuilder(@"   
                                    select 今日=isnull(sum(case when  DateDiff(dd,创建时间,getdate())=0   then 1 else 0 end ),0) ,
                                    本月=isnull(sum(case when DateDiff(month,创建时间,getdate())=0   then 1 else 0 end ),0) 
                                    from  TZTransferBill");
                StringBuilder crSb = new StringBuilder(@"   
                                    select 今日=isnull(sum(case when  DateDiff(dd,创建时间,getdate())=0   then 1 else 0 end ),0) ,
                                    本月=isnull(sum(case when DateDiff(month,创建时间,getdate())=0   then 1 else 0 end ),0) 
                                    from  TZInfectBill");
                DataSet ds = DataSetUtility.GetDataSetFromCDB(sb);
                DataSet ptDs = DataSetUtility.GetDataSetFromCDB(ptSb);
                DataSet crDs = DataSetUtility.GetDataSetFromCDB(crSb);
                
                if (ds.Tables[0].Rows.Count>0&& ptDs.Tables[0].Rows.Count > 0&& crDs.Tables[0].Rows.Count > 0) {
                    toldList = new List<ToldStatistics>();
                    toldList.Add(new ToldStatistics()
                    {
                        name = "衔接推送统计",
                        count = NullConvert.IntNullDispose(ds.Tables[0].Rows[0]["今日"].ToString())
                    });
                    toldList.Add(new ToldStatistics()
                    {
                        name = "普通转院申请",
                        count = NullConvert.IntNullDispose(ptDs.Tables[0].Rows[0]["今日"].ToString())
                    });
                    toldList.Add(new ToldStatistics()
                    {
                        name = "传染病转申请",
                        count = NullConvert.IntNullDispose(crDs.Tables[0].Rows[0]["今日"].ToString())
                    });
                    toldDTO = new ToldStatisticsDTO()
                    {
                        name = "day",
                        list = toldList
                    };
                    toldDTOList.Add(toldDTO);

                    toldList = new List<ToldStatistics>();
                    toldList.Add(new ToldStatistics()
                    {
                        name = "衔接推送统计",
                        count = NullConvert.IntNullDispose(ds.Tables[0].Rows[0]["本月"].ToString())
                    });
                    toldList.Add(new ToldStatistics()
                    {
                        name = "普通转院申请",
                        count = NullConvert.IntNullDispose(ptDs.Tables[0].Rows[0]["本月"].ToString())
                    });
                    toldList.Add(new ToldStatistics()
                    {
                        name = "传染病转申请",
                        count = NullConvert.IntNullDispose(crDs.Tables[0].Rows[0]["本月"].ToString())
                    });
                    toldDTO = new ToldStatisticsDTO()
                    {
                        name = "month",
                        list = toldList
                    };
                    toldDTOList.Add(toldDTO);
                }
                responseData.data = toldDTOList;
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetToldStatistics", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }
        #endregion

        #region 病情分级列表的接口
        public ResponseDataDTO GetDiseaseLevelList(string dateType)
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取病情分级列表成功！" };
            List<DiseaseLevelDTO> list = new List<DiseaseLevelDTO>();
            try
            {

                switch (dateType)
                {
                    case "month":
                        dateType = "mm";
                        break;
                    case "date":
                        dateType = "dd";
                        break;
                    default:
                        dateType = "mm";
                        break;
                }
                StringBuilder sb = new StringBuilder($"select th.医院简称 as name," +
                    $"(select Max(MaxLevel) from (values(tp.初诊评级结果),(tp.交接前评级结果),(tp.院内评级结果)) as #temp(MaxLevel)) as level" +
                    $" from  THospitalBaseInfo th" +
                    $" left join  TToldInfo  tt  on   th.医院编码=tt.医院编码" +
                    $" left join  TPatientLevel tp  on  tt.告知单编码=tp.告知单编码" +
                    $" where  tp.告知单编码 is not null and DateDiff({dateType},tt.创建时间,getdate())=0 and th.是否有效=1" +
                    $" group  by  th.医院简称,tp.初诊评级结果,tp.交接前评级结果,tp.院内评级结果");
                DataSet ds = DataSetUtility.GetDataSetFromCDB(sb);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    var levelDTOList = ModelConvertHelper<DiseaseLevelDTO>.ConvertToModel(ds.Tables[0]);
                    var groupList = levelDTOList.GroupBy(x => x.name).ToList();
                    foreach (var item in groupList)
                    {
                        DiseaseLevelDTO levelDTO = new DiseaseLevelDTO();
                        levelDTO.name = item.Key;
                        levelDTO.I = item.ToList().Count(x => x.level == 0).ToString();
                        levelDTO.II = item.ToList().Count(x => x.level == 1).ToString();
                        levelDTO.III = item.ToList().Count(x => x.level == 2).ToString();
                        levelDTO.IV = item.ToList().Count(x => x.level == 3).ToString();
                        list.Add(levelDTO);
                    }
                }
                else {
                    list.Add(new DiseaseLevelDTO() {
                        name = "",
                        I="0",
                        II="0",
                        III="0",
                        IV="0",
                        level=0
                    });
                }
                responseData.data = list;
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetDiseaseLevelList", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }

        #endregion

        #region 衔接统计疾病分类
        public ResponseDataDTO GetDiseaseTypeList(string dateType)
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取衔接统计疾病分类成功！" };
            List<DiseaseTypeDTO> list = new List<DiseaseTypeDTO>();
            try
            {
                switch (dateType)
                {
                    case "month":
                        dateType = "mm";
                        break;
                    case "date":
                        dateType = "dd";
                        break;
                    default:
                        dateType = "dd";
                        break;
                }
                StringBuilder sb = new StringBuilder($"select   case 现场判断 when  '胸痛'  then  '胸痛'" +
                    $" when  '卒中'  then  '卒中' " +
                    $" when  '创伤'  then  '创伤' " +
                    $" when  '中毒'  then  '中毒' " +
                    $" when  '新生儿'  then  '新生儿' " +
                    $" when  '孕妇'  then  '孕妇'" +
                    $" when  '其他'  then  '其他'" +
                    $" else ''end  as name, isnull(count(现场判断),0) as  count" +
                    $" from  TToldInfo where 现场判断 is not null and  DateDiff({dateType},创建时间,getdate())=0 group by 现场判断");
                DataSet ds = DataSetUtility.GetDataSetFromCDB(sb);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    list = ModelConvertHelper<DiseaseTypeDTO>.ConvertToModel(ds.Tables[0]);
                    var nameList = list.Select(x => x.name).ToList();
                    if (!nameList.Contains(EnumHelper.GetEnumDesc(JudgementEnum.J2)))
                    {
                        list.Add(new DiseaseTypeDTO()
                        {
                            name = EnumHelper.GetEnumDesc(JudgementEnum.J2),
                            count = 0
                        });
                    }
                    if (!nameList.Contains(EnumHelper.GetEnumDesc(JudgementEnum.J3)))
                    {
                        list.Add(new DiseaseTypeDTO()
                        {
                            name = EnumHelper.GetEnumDesc(JudgementEnum.J3),
                            count = 0
                        });
                    }
                    if (!nameList.Contains(EnumHelper.GetEnumDesc(JudgementEnum.J4)))
                    {
                        list.Add(new DiseaseTypeDTO()
                        {
                            name = EnumHelper.GetEnumDesc(JudgementEnum.J4),
                            count = 0
                        });
                    }
                    if (!nameList.Contains(EnumHelper.GetEnumDesc(JudgementEnum.J5)))
                    {
                        list.Add(new DiseaseTypeDTO()
                        {
                            name = EnumHelper.GetEnumDesc(JudgementEnum.J5),
                            count = 0
                        });
                    }
                    if (!nameList.Contains(EnumHelper.GetEnumDesc(JudgementEnum.J6)))
                    {
                        list.Add(new DiseaseTypeDTO()
                        {
                            name = EnumHelper.GetEnumDesc(JudgementEnum.J6),
                            count = 0
                        });
                    }
                    if (!nameList.Contains(EnumHelper.GetEnumDesc(JudgementEnum.J7)))
                    {
                        list.Add(new DiseaseTypeDTO()
                        {
                            name = EnumHelper.GetEnumDesc(JudgementEnum.J7),
                            count = 0
                        });
                    }

                }
                else
                {
                    list.Add(new DiseaseTypeDTO()
                    {
                        name = EnumHelper.GetEnumDesc(JudgementEnum.J2),
                        count = 0
                    });
                    list.Add(new DiseaseTypeDTO()
                    {
                        name = EnumHelper.GetEnumDesc(JudgementEnum.J3),
                        count = 0
                    });
                    list.Add(new DiseaseTypeDTO()
                    {
                        name = EnumHelper.GetEnumDesc(JudgementEnum.J4),
                        count = 0
                    });
                    list.Add(new DiseaseTypeDTO()
                    {
                        name = EnumHelper.GetEnumDesc(JudgementEnum.J5),
                        count = 0
                    });
                    list.Add(new DiseaseTypeDTO()
                    {
                        name = EnumHelper.GetEnumDesc(JudgementEnum.J6),
                        count = 0
                    });
                    list.Add(new DiseaseTypeDTO()
                    {
                        name = EnumHelper.GetEnumDesc(JudgementEnum.J7),
                        count = 0
                    });
                }
                List<string> orderList = new List<string>() {
                    EnumHelper.GetEnumDesc(JudgementEnum.J2),
                    EnumHelper.GetEnumDesc(JudgementEnum.J3),
                    EnumHelper.GetEnumDesc(JudgementEnum.J4),
                    EnumHelper.GetEnumDesc(JudgementEnum.J5),
                    EnumHelper.GetEnumDesc(JudgementEnum.J6),
                    EnumHelper.GetEnumDesc(JudgementEnum.J7),
                    EnumHelper.GetEnumDesc(JudgementEnum.J1),
                    EnumHelper.GetEnumDesc(JudgementEnum.J8)
                };
                List<DiseaseTypeDTO> list1 = new List<DiseaseTypeDTO>();
                foreach (var item in orderList)
                {

                    list.ForEach(item1 =>
                    {
                        if (item1.name == item)
                        {
                            list1.Add(item1);
                        }
                    });
                }
                responseData.data = list1;
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetDiseaseTypeList", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }

        #endregion

        #region 医院信息接口
        public ResponseDataDTO GetHospitalInfo(string id)
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取医院信息成功！" };
            try
            {
                HospitalInfoDTO hospitalInfoDTO = new HospitalInfoDTO();
                SqlParameter sp = new SqlParameter("@ID", id);
                StringBuilder sb = new StringBuilder(@"
                                select thbi.突发事件接诊能力,thbi.突发事件一级接诊能力,thbi.突发事件二级接诊能力,
                                thbi.突发事件三级接诊能力,thrti.急诊开放状态,
                                thrti.急诊挂号人数,thbi.呼吸机,thbi.洗胃机,
                                thrti.抢救室床位,thrti.留观室床位,thrti.神内导管室,thrti.心内导管室,
                                thrti.三级患者等候人数,thrti.四级患者等候人数,
                                thrti.抢救室使用量,thrti.留观使用量,thrti.神内使用量,thrti.心内使用量
                                from [dbo].[THospitalBaseInfo] thbi
                                left join [dbo].[THospitalRealTimeInfo] thrti on thbi.医院编码=thrti.医院编码
                                where thbi.医院编码=@ID

                                select t.科室类型,tzd.名称 as 科室类型名称,t.科室名称,t.备注,t.是否24小时开放,t.急诊出诊医生数
                                from [dbo].[THospitalDepartment] t
                                left join TZDictionary tzd on t.科室类型=tzd.编码
                                where t.医院编码=@ID

                                select t.能力类型,tzd.名称 as 能力类型名称,t.能力名称,t.是否24小时开放,t.备注
                                from [dbo].[THospitalAbilityInfo] t
                                left join TZDictionary tzd on t.能力类型=tzd.编码
                                where t.医院编码=@ID
                                ");
                DataSet ds = DataSetUtility.GetDataSetFromCDB(sb, sp);
                if (ds.Tables.Count > 0)
                {

                    //接诊能力
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];
                        HospitalAbleList hospitalAble = new HospitalAbleList();
                        hospitalAble.aidOpenState = dr["急诊开放状态"].ToString()=="1"?"正常":"不正常";
                        hospitalAble.emergencyAcceptable = dr["突发事件接诊能力"].ToString();
                        List<AcceptableOtherList> otherList = new List<AcceptableOtherList>();
                        otherList.Add(new AcceptableOtherList()
                        {
                            name = "急诊挂号人数",
                            count = NullConvert.IntNullDispose(dr["急诊挂号人数"].ToString())
                        });
                        otherList.Add(new AcceptableOtherList()
                        {
                            name = "呼吸机",
                            count = NullConvert.IntNullDispose(dr["呼吸机"].ToString())
                        });
                        otherList.Add(new AcceptableOtherList()
                        {
                            name = "洗胃机",
                            count = NullConvert.IntNullDispose(dr["洗胃机"].ToString())
                        });
                        hospitalAble.acceptableOtherList = otherList;

                        List<AcceptableList> acceptableList = new List<AcceptableList>();
                        acceptableList.Add(new AcceptableList()
                        {
                            name = "红",
                            Acolor = "#db373a",
                            APercent = DealDataToPercent(dr["突发事件一级接诊能力"], dr["突发事件接诊能力"]),
                            count = NullConvert.IntNullDispose(dr["突发事件一级接诊能力"].ToString())
                        });
                        acceptableList.Add(new AcceptableList()
                        {
                            name = "黄",
                            Acolor = "#db9737",
                            APercent = DealDataToPercent(dr["突发事件二级接诊能力"], dr["突发事件接诊能力"]),
                            count = NullConvert.IntNullDispose(dr["突发事件二级接诊能力"].ToString())
                        });
                        acceptableList.Add(new AcceptableList()
                        {
                            name = "绿",
                            Acolor = "#059b6b",
                            APercent = DealDataToPercent(dr["突发事件三级接诊能力"], dr["突发事件接诊能力"]),
                            count = NullConvert.IntNullDispose(dr["突发事件三级接诊能力"].ToString())
                        });
                        hospitalAble.acceptableList = acceptableList;
                        hospitalInfoDTO.hospitalAbleList = hospitalAble;

                        //急诊单元
                        HospitalUnitList hospitalUnitList = new HospitalUnitList();
                        List<AidBedList> aidBedList = new List<AidBedList>();
                        List<PatientAreaList> patientAreaList = new List<PatientAreaList>();
                        aidBedList.Add(new AidBedList()
                        {
                            BedName = "抢救室床位",
                            BedUsed = NullConvert.IntNullDispose(dr["抢救室使用量"].ToString()),
                            BedSum = NullConvert.IntNullDispose(dr["抢救室床位"].ToString()),
                            BedPercent = DealDataToPercent(dr["抢救室使用量"], dr["抢救室床位"]),
                            Remaining = DealDataToRemaining(dr["抢救室使用量"], dr["抢救室床位"]),
                            BedColor = ConvertDegreeToColor(DealDataToPercent(dr["抢救室使用量"], dr["抢救室床位"]))
                        });
                        aidBedList.Add(new AidBedList()
                        {
                            BedName = "留观室床位",
                            BedUsed = NullConvert.IntNullDispose(dr["留观使用量"].ToString()),
                            BedSum = NullConvert.IntNullDispose(dr["留观室床位"].ToString()),
                            BedPercent = DealDataToPercent(dr["留观使用量"], dr["留观室床位"]),
                            Remaining = DealDataToRemaining(dr["留观使用量"], dr["留观室床位"]),
                            BedColor = ConvertDegreeToColor(DealDataToPercent(dr["留观使用量"], dr["留观室床位"]))
                        });
                        aidBedList.Add(new AidBedList()
                        {
                            BedName = "心内导管室",
                            BedUsed = NullConvert.IntNullDispose(dr["心内使用量"].ToString()),
                            BedSum = NullConvert.IntNullDispose(dr["心内导管室"].ToString()),
                            BedPercent = DealDataToPercent(dr["心内使用量"], dr["心内导管室"]),
                            Remaining = DealDataToRemaining(dr["心内使用量"], dr["心内导管室"]),
                            BedColor = ConvertDegreeToColor(DealDataToPercent(dr["心内使用量"], dr["心内导管室"]))
                        });
                        aidBedList.Add(new AidBedList()
                        {
                            BedName = "神内导管室",
                            BedUsed = NullConvert.IntNullDispose(dr["神内使用量"].ToString()),
                            BedSum = NullConvert.IntNullDispose(dr["神内导管室"].ToString()),
                            BedPercent = DealDataToPercent(dr["神内使用量"], dr["神内导管室"]),
                            Remaining = DealDataToRemaining(dr["神内使用量"], dr["神内导管室"]),
                            BedColor = ConvertDegreeToColor(DealDataToPercent(dr["神内使用量"], dr["神内导管室"]))
                        });
                        hospitalUnitList.aidBedList = aidBedList;

                        patientAreaList.Add(new PatientAreaList()
                        {
                            name= "III级病人",
                            value= NullConvert.IntNullDispose(dr["三级患者等候人数"].ToString()),
                        });
                        patientAreaList.Add(new PatientAreaList()
                        {
                            name= "IV级病人",
                            value= NullConvert.IntNullDispose(dr["四级患者等候人数"].ToString()),
                        });
                        hospitalUnitList.patientAreaList = patientAreaList;

                        hospitalInfoDTO.hospitalUnitList = hospitalUnitList;
                    }


                    // 科室能力
                    if (ds.Tables[1].Rows.Count > 0)
                    {
                        List<DepartInfoList> departInfoList = new List<DepartInfoList>();
                        List<DepartInfo> list = new List<DepartInfo>();
                        foreach (DataRow dr in ds.Tables[1].Rows)
                        {
                            //DepartInfoList departInfo = new DepartInfoList();
                            DepartInfo departInfo = new DepartInfo();
                            departInfo.name = dr["科室名称"].ToString();
                            departInfo.type = dr["科室类型名称"].ToString();
                            departInfo.opened = Convert.ToBoolean(dr["是否24小时开放"]);
                            departInfo.remark = dr["备注"].ToString();
                            departInfo.aidNum = Convert.ToInt32(dr["急诊出诊医生数"]);
                            list.Add(departInfo);
                        }
                        var listGB = list.GroupBy(q => q.type).ToList();
                        foreach (var item in listGB)
                        {
                            DepartInfoList departInfo = new DepartInfoList();
                            departInfo.typeName = item.Key;
                            departInfo.list = item.ToList();
                            departInfoList.Add(departInfo);
                        }
                        hospitalInfoDTO.departInfoList = departInfoList;
                    }

                    //救治能力
                    if (ds.Tables[2].Rows.Count > 0)
                    {
                        List<HospitalAidableList> hospitalAidableList = new List<HospitalAidableList>();
                        List<DepartInfo> list = new List<DepartInfo>();
                        foreach (DataRow dr in ds.Tables[2].Rows)
                        {
                            DepartInfo departInfo = new DepartInfo();
                            departInfo.name = dr["能力名称"].ToString();
                            departInfo.type = dr["能力类型名称"].ToString();
                            departInfo.opened = Convert.ToBoolean(dr["是否24小时开放"]);
                            departInfo.remark = dr["备注"].ToString();
                            list.Add(departInfo);
                        }
                        var listGB=list.GroupBy(x => x.type).ToList();
                        foreach (var item in listGB)
                        {
                            HospitalAidableList hospitalAidable = new HospitalAidableList();
                            hospitalAidable.typeName = item.Key;
                            hospitalAidable.list = item.ToList();
                            hospitalAidableList.Add(hospitalAidable);
                        }
                        hospitalInfoDTO.hospitalAidableList = hospitalAidableList;
                    }
                    responseData.data = hospitalInfoDTO;
                }
            }
            catch (Exception ex)
            {
                LogUtility.Error("HospitalInfoDAL/GetHospitalInfo", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }

        #endregion


        #region 车辆GPS信息接口
        public ResponseDataDTO GetAmbulanceGPSList()
        {
            ResponseDataDTO responseData = new ResponseDataDTO() { status = ResultCode.Success, message = "获取车辆GPS信息成功！" };
            List<TGPSDTO> list = new List<TGPSDTO>();
            try
            {
                
                StringBuilder sb = new StringBuilder(@"   
                                  select tg.车辆编码,tzs.名称 as 车辆状态,tg.时间,tg.经度,tg.纬度,tg.高度,tg.速度,tg.方向,ta.车牌号码 as 车牌号,ta.实际标识 as 实际标识 from TGPSLast  tg
                                  left join  TAmbulance  ta   on   tg.车辆编码=ta.车辆编码
                                  left join TZAmbulanceState  tzs  on   tg.工作状态编码=tzs.编码
								  left join TTask  tt  on  ta.任务编码=tt.任务编码
                                  left join TStation  ts  on  ts.编码=tt.分站编码
								  where tt.是否执行中=1");
                DataSet ds = DataSetUtility.GetDataSetFromMain(sb);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        TGPSDTO taskDTO = new TGPSDTO();
                        taskDTO.ambCode = dr["车辆编码"].ToString();
                        taskDTO.ambState = dr["车辆状态"].ToString();
                        taskDTO.gpsTime = dr["时间"].ToString();
                        if (dr["纬度"].ToString() == "0" && dr["经度"].ToString() == "0")
                        {
                            taskDTO.ambX = 0;
                            taskDTO.ambY = 0;
                        }
                        else
                        {
                            //转成百度GPS
                            double[] coordinate = CoorConvert.Gps84ToBd09(Convert.ToDouble(dr["纬度"]), Convert.ToDouble(dr["经度"]));
                            taskDTO.ambY = coordinate[0];
                            taskDTO.ambX = coordinate[1];
                        }

                        taskDTO.height = NullConvert.DoubleNullDispose(dr["高度"].ToString());
                        taskDTO.speed = NullConvert.DoubleNullDispose(dr["速度"].ToString());
                        taskDTO.direction = NullConvert.DoubleNullDispose(dr["方向"].ToString());
                        taskDTO.ambNum = dr["车牌号"].ToString();
                        taskDTO.ambRealSign = dr["实际标识"].ToString();
                        list.Add(taskDTO);
                    }
                }
                responseData.data = list;
            }
            catch (Exception ex)
            {
                LogUtility.Error("TaskDAL/GetAmbulanceGPSInfo", ex.ToString());//记日志
                responseData.status = ResultCode.Fail;
                responseData.message = "获取失败";
            }
            return responseData;
        }
        #endregion


        /// <summary>
        /// 处理数据百分比
        /// </summary>
        /// <param name="val"></param>
        /// <param name="sum"></param>
        /// <returns></returns>
        public double DealDataToPercent(object val, object sum)
        {
            double ret = 0;
            if (!(val is DBNull) && !(sum is DBNull))
            {
                int intSum = Convert.ToInt32(sum.ToString());
                if (intSum != 0)
                {
                    int intVal = Convert.ToInt32(val.ToString());
                    double dblVal = intVal * 100.0 / intSum;
                    ret = Math.Round(dblVal, 0, MidpointRounding.AwayFromZero);
                    //ret = ret >= 100 ? 100 : ret;
                }
            }
            return ret;
        }

        /// <summary>
        /// 百分比颜色处理
        /// </summary>
        /// <param name="degree"></param>
        /// <returns></returns>
        public string ConvertDegreeToColor(double degree)
        {
            string color = "";
            if (degree >= 100)
            {
                color = "#e51728";
            }
            else if (degree >= 70)
            {
                color = "#fca832";
            }
            else
            {
                //color = "#01ded3";
                color = "#2ee62e";
            }
            return color;
        }


        public int DealDataToRemaining(object val, object sum)
        {
            int ret = 0;
            if (!(val is DBNull) && !(sum is DBNull))
            {
                int intSum = Convert.ToInt32(sum.ToString());
                if (intSum != 0)
                {
                    int intVal = Convert.ToInt32(val.ToString());
                    ret = intSum - intVal;
                }
            }
            return ret;
        }

        /// <summary>
        /// 获取字典表数据
        /// </summary>
        /// <returns></returns>
        private List<TZDictionary> GetTZDictionary()
        {
            List<TZDictionary> dicList = new List<TZDictionary>();
            try
            {
                StringBuilder sb = new StringBuilder(" select * from TZDictionary where 1 = 1");
                DataSet ds = DataSetUtility.GetDataSetFromCDB(sb);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        TZDictionary tZDictionary = new TZDictionary()
                        {
                            id = dr["编码"].ToString(),
                            name = dr["名称"].ToString(),
                            typeID = dr["类型编码"].ToString(),
                            orderID = Convert.ToInt32(dr["顺序号"].ToString()),
                            isValid = dr["是否有效"].ToString()
                        };
                        dicList.Add(tZDictionary);
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtility.Error("DictionaryDAL/GetTZDictionary", ex.ToString());
            }
            return dicList;
        }
    }
}
